{
    // 基本示例
    let arr = ['hello', 'world'];
    let map = arr[Symbol.iterator](); //直接调用
    console.log(map.next());
    console.log(map.next());
    console.log(map.next());
}

{
    // 自定义数据结构; 增加iterator数据接口
    let obj = {
        start: [1, 3, 2],
        end: [7, 9, 8],
        demo(){
            console.log('es6 新增写法')
        },
        [Symbol.iterator]() {
            let self = this;
            let index = 0;
            let arr = self.start.concat(self.end);
            let len = arr.length;
            return {
                next() {
                    if (index < len) {
                        return {
                            value: arr[index++],
                            done: false
                        }
                    } else {
                        return {
                            value: arr[index++],
                            done: true
                        }
                    }
                }
            }
        }
    }

    let objDemo = {
        start: [1, 3, 2],
        end: [7, 9, 8],
    }
    obj.start = ['s','wwd','de','d']

    for (let key of obj) {
        console.log(key); // 返回具体的每一个数组中的值
    }

    // next 调用
    var map = obj[Symbol.iterator]();
    console.log("iterator",map.next());
    console.log("iterator",map.next());
    console.log("iterator",map.next());
    console.log("iterator",map.next());

    // 用 for...of 报错
    for (let key in objDemo) {
        console.log(key); // 返回key值start end
    }
}